import 'dart:async';
import 'package:bloc_pattern/bloc_pattern.dart';
import 'package:flutter_food_delivery_app_ui/model/food_item.dart';
import 'package:rxdart/rxdart.dart';

import 'cart_provider.dart';

class CartListBlocController extends BlocBase {

  CartListBlocController();

//Stream that receives a number and changes the count;
  var _listController = BehaviorSubject<List<FoodItem>>.seeded([]);
//output
  Stream<List<FoodItem>> get outListStream => _listController.stream;
//input
  Sink<List<FoodItem>> get inListStream => _listController.sink;

  CartProvider cardProvider = CartProvider();

  addToList(FoodItem foodItem){
    List<FoodItem> list = cardProvider.addToList(foodItem);
    inListStream.add(list);
  }

  removeFromList(FoodItem foodItem){
    inListStream.add(cardProvider.removeFrom(foodItem));
  }

//dispose will be called automatically by closing its streams
  @override
  void dispose() {
    _listController.close();
    super.dispose();
  }

}
